class LWWSInfo {
  String URL;
  PImage orgImage;
  PImage newImage;
  float x;
  float y;
  int step;
  int w;
  int h;
  String temperature;

  void LWWSInfo (String _URL, PImage _orgImage, String _temperature, float startX, float startY, int _step) 
  {
    URL = _URL;
    orgImage = _orgImage;    
    convertImage(); // create newImage
    temperature = _temperature;
    x = startX;
    y = startY;
    w = newImage.width;
    h = newImage.height;
    step = _step;
  }
  void display() {
    image (newImage , x, y);
  }
  void move() {
    x = x - step;
  }
  void convertImage() {
    newImage = createImage(orgImage.width, orgImage.height, ARGB);

    orgImage.loadPixels();
    newImage.loadPixels();
    color blendedColor;

    for ( int i=0 ; i < orgImage.pixels.length ; i++){
      boolean isEdge = false ;
      // println ("   pixcel "+i + ": " + orgImage.pixels[i]);

      //float sat = saturation(orgImage.pixels[i]) ;
      //println("Saturation," + i + "," + sat);

      // if background (assume white)
      if ( orgImage.pixels[i] == color(255,255,255) ){
        newImage.pixels[i] = color(255,0);
      } 
      else 
      {
        // left edge
        if ( i < orgImage.pixels.length -1  && orgImage.pixels[i+1] == color(255,255,255)) {
          isEdge = true;
        } 
        // right edge
        else if ( i > 0  && orgImage.pixels[i-1] == color(255,255,255)) {
          isEdge = true;
        }
        // top edge
        else if ( (i - orgImage.width) >= 0   && orgImage.pixels[i-orgImage.width] == color(255,255,255)) {
          isEdge = true;
        }
        // bottom edge
        else if (( (i + orgImage.width) < orgImage.pixels.length   && orgImage.pixels[i+orgImage.width] == color(255,255,255)) || (i + orgImage.width) > orgImage.pixels.length ) {
          isEdge = true;
        }
        if (isEdge) {
          float a_value = saturation(orgImage.pixels[i]) ;
          // println ("i " + i + " / a_value:" +a_value); 
          newImage.pixels[i] = color (red(orgImage.pixels[i]), green(orgImage.pixels[i]), blue(orgImage.pixels[i]), a_value);
        }
        else {
          newImage.pixels[i] = orgImage.pixels[i];
        }
      }
    }
    orgImage.updatePixels();
    newImage.updatePixels();


  }
}






